<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
	<title>权限管理</title>
	<style type="text/css">
	span{
		display:inline-block;
	}
	
	span label{
		display:inline-block;
	}
	.controls label{
		display:inline-block;
	}
	</style>
	<script>
		$(document).ready(function() {
			$("#authCode").focus();
			var actionId = '${actionId}';
			if(actionId=="1"){
				$("input:radio[value=A]").attr('checked','true');
			}
			$("#inputForm").validate({
				rules: {
   					authCode: {
						required:true,
						rangelength:[1,30],
						remote:{ 
　　		 					type: "get",  //数据发送方式   
                            dataType: "json",       //接受数据格式      
　　							url:"${ctx}/user/auth/checkCode",
　　	 						data:{
　　								authCode:function(){
									return $("#authCode").val();
　　								}
							}
						}                             
					},
					authName:{
						required:true
					}
  				},
        		messages: {
   					authCode: {
						required:"权限编码不能为空！",
						rangelength:jQuery.format("权限编码位数必须在{0}到{1}字符之间！"),
						remote:jQuery.format("权限编码已经被使用")
					},
					authName:{
						required:"权限名称不能为空！"
					}
  				}
			});
			$("#submitBtn").click(function(){
		    	if($("#inputForm").valid()){
		    		if(!checkRadio()){
						alert("权限类型为必填项,请选择");
						return false;
					}
					if(actionId=="1"){
						document.inputForm.action = "${ctx}/user/auth/save";
					}else if(actionId=="2"){
						document.inputForm.action = "${ctx}/user/auth/update";
					}
		     		$("#inputForm").submit();
		 		}
			});
		});
		//检查权限类型
		function checkRadio(){
			var val=$('input:radio[name="authType"]:checked').val(); 
			if(val==null){ 
                return false; 
            } 
           	return true;
		}
	</script>
</head>

<body>
       	<div>
               <div id="jCrumbs" class="breadCrumb module">
 					<ul>
		        <li>
		            <a href="#"><i class="icon-home" style="margin-top: 2px;"></i></a>
		        </li>
		        <li>
		            	权限管理
		        </li>
		         <li>
		            <a href="${ctx}/user/auth">权限列表</a>
		        </li>
		        <li>
		            	权限编辑
		        </li>
		    </ul>
		</div>					                    
	<div class="row-fluid">
 			<div class="span12">
 			<div style="float:right">
				<button class="btn" type="button"  onclick="back()">返 回</button>
			</div>
      		<h3 class="heading">权限信息</h3>
			<div class="row-fluid">
				<div class="span8">
						<form:form id="inputForm" name="inputForm" modelAttribute="auth" cssClass="form-horizontal"
								action="" method="post">
							<input type="hidden" name="authId" id="authId" value="${auth.authId}"/>	
							<input type="hidden" name="sortId" id="sortId" value="${auth.sortId}"/>										
							<fieldset>
								<div class="control-group formSep">
									<label for="u_fname" class="control-label"><font color="red">*</font>权限编码:</label>
									<c:if test="${actionId=='1'}">
	                					<div class="controls">
											<input type="text" id="authCode" name="authCode" class="input-xlarge" value="${auth.authCode}" />
										</div>
	                				</c:if>
	                				<c:if test="${actionId=='2'}">
	                					<input type="hidden" name="authCode"  id="authCode1" class="input2" value="${auth.authCode}"/>
	                					
	                					<div class="controls text_line">
											<strong>${auth.authCode}</strong>
										</div>
	                				</c:if>
								</div>
								<div class="control-group formSep">
									<label for="fileinput" class="control-label"><font color="red">*</font>权限名称:</label>
									<div class="controls">
										<input type="text" id="authName" name="authName" class="input-xlarge" value="${auth.authName}" />
									</div>
								</div>
								<div class="control-group formSep">
									<label class="control-label"><font color="red">*</font>权限类型:</label>
									<div class="controls">
										<form:radiobuttons path="authType" items="${allAuthType}" itemLabel="typeText" itemValue="typeValue" />
									</div>
								</div>
								<div class="control-group formSep">
									<label for="fileinput" class="control-label">权限父编码:</label>
									<div class="controls">
										<input type="text" id="authParentCode" name="authParentCode" class="input-xlarge" value="${auth.authParentCode}" />
									</div>
								</div>
								<div class="control-group formSep">
									<label for="fileinput" class="control-label">菜单地址:</label>
									<div class="controls">
										<input type="text" id="menuAddr" name="menuAddr" class="input-xlarge" value="${auth.menuAddr}" />
									</div>
								</div>
								<div class="control-group">
									<div class="controls">
										<button class="btn btn-gebo" type="button" id="submitBtn">保 存</button>
										<button class="btn" type="reset">重 置</button>
									</div>
								</div>
							</fieldset>
						</form:form>
					</div>
				</div>
   			</div>
		</div>
     </div>
</body>
</html>
